<template>
  <div>
    <!--  -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          class="bnt"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
    </el-row>
    <!-- 列表 -->
    <el-table
      v-loading="loading"
      :data="articlesList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="项目编码" align="center" prop="projectCode" />
      <el-table-column label="项目密钥" align="center" prop="projectKey">
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="modifyTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :showSearch.sync="showSearch"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getData"
    />
    <el-dialog
      title="新增项目配置"
      :visible.sync="open"
      width="800px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名" prop="projectName">
              <el-input v-model="form.projectName" placeholder="请输入项目名" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="项目编号" prop="projectCode">
              <el-input
                v-model="form.projectCode"
                placeholder="请输入项目编号"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  orderprojectConfigquery,
  vacantHousetDel,
  projectConfigadd,
} from "@/api/system/xianmu";

export default {
  data() {
    return {
      // 查询参数
      articlesList: [],
      loading: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },

      // 开关
      form: {},
      total: 0,
      ids: [],
      open: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      formOne: {},
      openDelis: false,
      showSearch: true,
    };
  },
  mounted() {
    this.getData();
  },
  computed: {},
  methods: {
    getData() {
      orderprojectConfigquery(this.queryParams).then((res) => {
        this.total = res.total;
        this.loading = false;
        this.articlesList = res.rows;
      });
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    handleDelete(row) {
      const userIds = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return vacantHousetDel(userIds);
        })
        .then(() => {
          this.getData();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handleAdd() {
      this.open = true;
      listCopropertynfig(this.queryParams).then((res) => {
        this.arr = res.rows;
      });
    },
    // 提交
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          projectConfigadd(this.form).then((response) => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getData();
            this.form = {};
          });
        }
      });
    },
    cancel() {
      this.open = false;
      this.getData();
    },
  },
};
</script>

<style scoped>
.mb8 {
  margin-top: 10px;
  padding-left: 15px;
}
.bnt {
  margin-top: 5px;
}
.images {
  width: 70px;
  height: 70px;
}
</style>
